package com.demo.project.controller;

import com.demo.annotation.AutoWired;
import com.demo.project.entity.Account;
import com.demo.project.entity.Team;
import com.demo.project.service.TeamService;
import com.demo.project.utils.StringUtils;
import com.demo.result.R;
import com.demo.web.annotation.Controller;
import com.demo.web.annotation.RequestMapping;
import com.demo.web.annotation.RequestParam;
import com.demo.web.webenum.RequestType;

import java.util.List;
import java.util.Map;

/**
 * team应该有的操作
 * 1，发起组队 发起者为队长
 * 2，加入组队
 * 3，退出组队 组长为解散组队
 * 4，查看本队队员的信息
 * 5，查看相关的组队
 */
@Controller
@RequestMapping("/team")
public class TeamController {
    @AutoWired
    private TeamService teamService;

    @RequestMapping(value = "searchTeamCondition",type = RequestType.POST)
    public R searchTeamCondition(@RequestParam("team") com.demo.project.entity.vo.Team team){
        String s = StringUtils.generateTeamVoId(team);
        List<Team> teams=teamService.searchTeamByCondition(s);
        return R.success().data("teams", teams);
    }

    @RequestMapping(value = "createTeam",type = RequestType.POST)
    public R createTeam(@RequestParam("team")Team team){
        String teamId=teamService.createTeam(team);
        return R.success().data("teamId", teamId);
    }

    @RequestMapping(value = "getTeamById",type = RequestType.GET)
    public R getTeamById(@RequestParam("teamId")String teamId){
        Team team=teamService.getTeamById(teamId);
        return R.success().data("team", team);
    }

    @RequestMapping(value = "joinTeamByTeamId",type = RequestType.GET)
    public R joinTeamByTeamId(@RequestParam("teamId")String teamId,@RequestParam("uid")String uid){
        boolean isSuccess=teamService.joinTeamByTeamId(teamId,uid);
        return R.success().data("result", isSuccess);
    }
    @RequestMapping(value = "exitTeam",type = RequestType.GET)
    public R exitTeam(@RequestParam("teamId")String teamId,@RequestParam("uid")String uid){
        boolean isSuccess=teamService.exitTeam(teamId,uid);
        return R.success().data("result", isSuccess);
    }
    @RequestMapping(value = "getTeamNumbersInfo",type = RequestType.GET)
    public R getTeamNumbersInfo(@RequestParam("teamId")String teamId){
        List<Account>teams=teamService.getTeamNumberInfo(teamId);
        return R.success().data("teams", teams);
    }
    @RequestMapping(value = "getTeamIdByUid",type = RequestType.GET)
    public R getTeamIdByUid(@RequestParam("uid")String uid){
        String teamIdByUid = teamService.getTeamIdByUid(uid);
        return R.success().data("teamId", teamIdByUid);
    }
    @RequestMapping(value = "disBandTeam",type = RequestType.GET)
    public R disBandTeam(@RequestParam("teamId")String teamId,@RequestParam("uid")String uid){
        boolean isSuccess=teamService.disBandTeam(teamId,uid);
        return R.success().data("isSuccess", isSuccess);
    }

    @RequestMapping(value = "getAllTeam",type = RequestType.GET)
    public R getAllTeam(){
        Map<String, Team> teams=teamService.getAllTeam();
        return R.success().data("teams",teams);
    }


    public void setTeamService(TeamService teamService) {
        this.teamService = teamService;
    }
}
